package com.daxt.controller.index;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import com.daxt.model.dto.BaseQueryDto;
import com.daxt.model.service.archives.vo.ArchivesDoc;
import com.daxt.utils.ArchivesUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.daxt.common.result.Result;
import com.daxt.common.result.ResultCode;
import com.daxt.common.result.ResultUtil;
import com.daxt.mapper.archives.ArchivesTypeDocMapper;
import com.daxt.mapper.sys.ArchivesTypeMapper;
import com.daxt.model.service.archives.result.ArchivesCols;
import com.daxt.model.service.archives.vo.ArchivesType;
import com.daxt.model.service.archives.vo.ArchivesTypeDoc;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(tags = "获取列字段接口")
@RestController
public class ColsController {
	
	@Autowired
	private ArchivesTypeMapper archivesTypeMapper;
	@Autowired
	private ArchivesTypeDocMapper archivesTypeDocMapper;
	@ApiOperation(value = "获取字段", notes = "") 
	@GetMapping("/select/cols/{type}") 
	public Result<ArchivesCols> getCols(@ApiParam("doc dossier")@PathVariable("type")String type,@ApiParam("") @RequestParam(value = "typeId",required = false)String typeId,
			@ApiParam("") @RequestParam(value = "fondsId",required = false)String fondsId,
			@RequestParam(value = "colType", required = false) String colType){
		ArchivesCols archivesCols=new ArchivesCols();

		ArchivesType at = archivesTypeMapper.selectById(typeId);

		if(null != at) {
			QueryWrapper<ArchivesTypeDoc> col = new QueryWrapper<>();
			col.eq("extType", type);
			//if("import".equals(colType)) {
			//	col.eq("isEdit", "1");
			//}
			
			col.eq("typeId", at.getId());
			if("insert".equals(colType)) {
				col.eq("isInsert", "1");
			}else if("edit".equals(colType)) {
				col.eq("isEdit", "1");
			}else if("list".equals(colType)) {
				col.eq("isList", "1");
			}else if("import".equals(colType)) {
				col.eq("isImport", "1");
			}else if("export".equals(colType)) {
				col.eq("isExport", "1");
			}
			List<ArchivesTypeDoc> baseCols = archivesTypeDocMapper.selectList(col);
			 List<ArchivesTypeDoc> collect = baseCols.stream().sorted(Comparator.comparing(ArchivesTypeDoc::getSort)).collect(Collectors.toList());
			archivesCols.setDossierBaseList(collect);
		}
		return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), "", archivesCols);
	}
}
